home *** CD-ROM | disk | FTP | other *** search
/ Creative Computers / Creative Computers CD-ROM, Volume 1 (Legendary Design Technologies, Inc.)(1994).iso / shareware / fractals / fracblank / fracblank.c < prev    next >
C/C++ Source or Header  |  1994-11-17  |  62KB  |  3,047 lines

  1. /*
  2. **    FracBlank - AmigaDOS 2.04 commodities utility screenblanker
  3. **
  4. **    Copyright © 1991-1992 by Olaf `Olsen' Barthel
  5. **        All Rights Reserved
  6. **
  7. **    Cosmic flame fractal code derived from xlock source code
  8. **
  9. **    Copyright © 1988-1991 by Patrick J. Naughton.
  10. */
  11.  
  12.     /* Include the specific math pragmas/header files here (is there
  13.      * any way to figure this out by taking a look at undocumented
  14.      * predefined compiler symbols?).
  15.      */
  16.  
  17. #ifdef MATH_FFP
  18. #include <clib/mathtrans_protos.h>
  19. #include <proto/mathtrans.h>
  20. #include <mffp.h>
  21. #else
  22. #include <m68881.h>
  23. #endif    /* MATH_FFP */
  24.  
  25. #include <math.h>
  26.  
  27.     /* sin -45° = cos -45° (saves precious calculation time). */
  28.  
  29. #define deg45    (-0.707106781)
  30.  
  31.     /* Use a simple address trick instead of the predefined
  32.      * address in amiga.lib.
  33.      */
  34.  
  35. #ifndef custom
  36. #define custom (*(struct Custom *)0xDFF000)
  37. #endif    /* custom */
  38.  
  39.     /* A couple of handy gadget control macros. */
  40.  
  41. #define GT_CHECKED(G)    ((((struct Gadget *)(G)) -> Flags & GFLG_SELECTED) ? TRUE : FALSE)
  42. #define GT_STRING(G)    (((struct StringInfo *)(((struct Gadget *)(G)) -> SpecialInfo)) -> Buffer)
  43.  
  44.     /* Hotkey IDs. */
  45.  
  46. enum    {    POP_WINDOW,BLANK_SCREEN };
  47.  
  48.     /* Gadget IDs. */
  49.  
  50. enum    {    GAD_SCREENTIMEOUT,GAD_MOUSETIMEOUT,GAD_PATTERNCHANGE,GAD_HOTKEY,
  51.         GAD_BLANKSCREEN,GAD_KEYBLANK,GAD_FRACTAL,GAD_COLOUR,GAD_HIDE,GAD_QUIT };
  52.  
  53.     /* Some useful signals. */
  54.  
  55. #define SIG_BREAK    SIGBREAKF_CTRL_C
  56. #define SIG_CHANGE    SIGBREAKF_CTRL_D
  57. #define SIG_CYCLE    SIGBREAKF_CTRL_E
  58. #define SIG_START    SIGBREAKF_CTRL_F
  59. #define SIG_REFRESH    SIGBREAKF_CTRL_E
  60. #define SIG_WAKEUP    SIGBREAKF_CTRL_F
  61. #define SIG_CX        (1 << CxPort -> mp_SigBit)
  62. #define SIG_WINDOW    (Window ? (1 << Window -> UserPort -> mp_SigBit) : NULL)
  63.  
  64.     /* Private mouse blanker signals. */
  65.  
  66. #define SIG_NOTICE    SIGBREAKF_CTRL_D
  67. #define SIG_ON        SIGBREAKF_CTRL_E
  68. #define SIG_OFF        SIGBREAKF_CTRL_F
  69.  
  70.     /* Number of patches to install. */
  71.  
  72. #define NUM_PATCHES    (sizeof(PatchTable) / sizeof(struct PatchInfo))
  73.  
  74.     /* Cosmic flame fractal parameters. */
  75.  
  76. #define MAXFLAMELEVEL    20
  77. #define MAXTOTALPOINTS    20000
  78.  
  79.     /* Fractal types. */
  80.  
  81. enum    {    FRACTAL_REAL_PLANE,FRACTAL_COSMIC_FLAME,FRACTAL_RANDOM };
  82.  
  83.     /* Colour modes. */
  84.  
  85. enum    {    COLOUR_CYCLE,COLOUR_STATIC,COLOUR_MONO };
  86.  
  87.     /* A system library patch definition. */
  88.  
  89. struct PatchInfo
  90. {
  91.     APTR         NewRoutine;
  92.     LONG         Offset;
  93.     ULONG        *Destination;
  94. };
  95.  
  96.     /* A window identification node, also contains information
  97.      * on the currently selected pointer sprite.
  98.      */
  99.  
  100. struct WindowNode
  101. {
  102.     struct MinNode     Node;
  103.  
  104.     struct Window    *Window;
  105.  
  106.     UWORD        *Pointer;
  107.     BYTE         Height,
  108.              Width;
  109.     BYTE         XOffset,
  110.              YOffset;
  111.     BYTE         Off;
  112. };
  113.  
  114.     /* The offsets of the system library routines we will patch. */
  115.  
  116. extern ULONG __far     LVOClearPointer,
  117.              LVOSetPointer,
  118.              LVOOpenWindow,
  119.              LVOOpenWindowTagList,
  120.              LVOCloseWindow;
  121.  
  122.     /* Program revision tag. */
  123.  
  124. STATIC const UBYTE VersTag[] = "\0$VER: FracBlank 2.2 (4.4.92)";
  125.  
  126.     /* Shared library identifiers. */
  127.  
  128. extern struct ExecBase    *SysBase;
  129.  
  130. struct IntuitionBase    *IntuitionBase;
  131. struct GfxBase        *GfxBase;
  132. struct Library        *CxBase,
  133.             *IconBase,
  134.             *GadToolsBase,
  135.             *UtilityBase;
  136.  
  137.     /* The main program. */
  138.  
  139. struct Process        *MainProcess;
  140.  
  141.     /* Blanker data. */
  142.  
  143. struct Task        *BlankTask;
  144. struct Screen        *BlankScreen;
  145.  
  146.     /* BlankerControl data. */
  147.  
  148. struct Task        *BlankerControlTask;
  149.  
  150.     /* Mouse blanker data. */
  151.  
  152. struct Task        *MouseBlankerTask;
  153.  
  154.     /* Commodities interface data. */
  155.  
  156. struct MsgPort        *CxPort;
  157. CxObj            *Broker;
  158.  
  159.     /* Gfx and gadtools data. */
  160.  
  161. struct Screen        *DefaultScreen;
  162. APTR             VisualInfo;
  163. struct TextFont        *LocalFont;
  164. struct Gadget        *GadgetList;
  165. struct Gadget        *GadgetArray[GAD_QUIT + 1];
  166. struct Window        *Window;
  167.  
  168.     /* Window zoom data. */
  169.  
  170. struct IBox         ZoomData = { -1,-1,-1,-1 };
  171.  
  172.     /* Window dimensions. */
  173.  
  174. WORD             WindowWidth    = 284,
  175.              WindowHeight    = 113;
  176.  
  177.     /* Rainbow colour table. */
  178.  
  179. UWORD             Table[75];
  180.  
  181.     /* No colours at all. */
  182.  
  183. UWORD             Black[32];
  184.  
  185.     /* Declarations for cosmic flame blanker code. */
  186.  
  187. float             Flame[2][3][2];
  188. WORD             FlameLevel,
  189.              FlameAlternateForm,
  190.              FlameModulo;
  191. UWORD             FlameColourTable[32];
  192. BYTE             FlameWheel,
  193.              FlameColour;
  194. PLANEPTR         FlamePlane;
  195. ULONG             FlamePoints;
  196.  
  197.     /* Key sequence buffers. */
  198.  
  199. UBYTE             HotkeyBuffer[256],
  200.              BlankScreenBuffer[256];
  201.  
  202.     /* Screen and pattern change timeout. */
  203.  
  204. ULONG             ScreenCount    = 0,
  205.              PatternCount    = 0,
  206.              ScreenTimeout    = 60,
  207.              MouseTimeout    = 5,
  208.              PatternTimeout    = 60;
  209.  
  210.     /* A flag which tells us whether to blank the mouse pointer
  211.      * on a keypress or not.
  212.      */
  213.  
  214. BYTE             KeyBlank    = TRUE;
  215.  
  216.     /* Some kind of a semaphore to tell the blank task to stop drawing. */
  217.  
  218. BYTE             StopDrawing    = FALSE;
  219.  
  220.     /* The default font to be used by the control panel. */
  221.  
  222. struct TextAttr         DefaultFont;
  223. UBYTE             DefaultFontName[256];
  224. UWORD             DefaultFontWidth;
  225.  
  226.     /* The colours of a rainbow (well, with a bit of imagination, just
  227.      * 32 colours in this rainbow for now).
  228.      */
  229.  
  230. UWORD Rainbow[32] =
  231. {
  232.     0x0000,0x0F00,0x0F30,0x0F50,
  233.     0x0F70,0x0F90,0x0FB0,0x0FD0,
  234.     0x0FF0,0x0DF0,0x0BF0,0x09F0,
  235.     0x07F0,0x05F0,0x03F0,0x00F0,
  236.     0x00D1,0x00B3,0x0095,0x0077,
  237.     0x0059,0x003B,0x001D,0x000F,
  238.     0x010F,0x030F,0x050F,0x070F,
  239.     0x090F,0x0B0F,0x0D0F,0x0F0F
  240. };
  241.  
  242.     /* A new broker definition, Commodities needs this. */
  243.  
  244. struct NewBroker NewBroker =
  245. {
  246.     NB_VERSION,
  247.     "FracBlanker",
  248.     "Fractal Blanker v2.2",
  249.     "Screen Blanker",
  250.     NBU_NOTIFY | NBU_UNIQUE,
  251.     COF_SHOW_HIDE,
  252.     0,NULL,0
  253. };
  254.  
  255.     /* The fractal mode names. */
  256.  
  257. STRPTR FractalModes[] =
  258. {
  259.     "Real Plane",
  260.     "Cosmic Flame",
  261.     "Random",
  262.     NULL
  263. };
  264.  
  265.     /* The current fractal type. */
  266.  
  267. UBYTE    FractalType = FRACTAL_RANDOM;
  268.  
  269.     /* The colour mode names. */
  270.  
  271. STRPTR ColourModes[] =
  272. {
  273.     "Cycling Colours",
  274.     "Static Colours",
  275.     "Monochrome",
  276.     NULL
  277. };
  278.  
  279.     /* The current colour mode. */
  280.  
  281. UBYTE    ColourMode = COLOUR_CYCLE;
  282.  
  283.     /* Patch data. */
  284.  
  285. extern VOID __stdargs         StackOldSetPointer(struct Window *Window,UWORD *Pointer,WORD Height,WORD Width,WORD XOffset,WORD YOffset);
  286. extern VOID              NewSetPointer(VOID);
  287.  
  288. APTR                 OldSetPointer;
  289.  
  290. VOID            (* __asm OldClearPointer)(register __a0 struct Window *,register __a6 struct IntuitionBase *);
  291. struct Window *        (* __asm OldOpenWindowTagList)(register __a0 struct NewWindow *,register __a1 struct TagItem *,register __a6 struct IntuitionBase *);
  292. struct Window *        (* __asm OldOpenWindow)(register __a0 struct NewWindow *,register __a6 struct IntuitionBase *);
  293. VOID            (* __asm OldCloseWindow)(register __a0 struct Window *,register __a6 struct IntuitionBase *);
  294.  
  295.     /* Mouse blanker function prototypes. */
  296.  
  297. VOID __stdargs __saveds         StackNewSetPointer(struct Window *Window,UWORD *Pointer,WORD Height,WORD Width,WORD XOffset,WORD YOffset);
  298.  
  299. VOID __asm __saveds         NewClearPointer(register __a0 struct Window *Window);
  300. struct Window * __asm __saveds     NewOpenWindowTagList(register __a0 struct NewWindow *NewWindow,register __a1 struct TagItem *TagList);
  301. struct Window * __asm __saveds     NewOpenWindow(register __a0 struct NewWindow *NewWindow);
  302. VOID __asm __saveds         NewCloseWindow(register __a0 struct Window *Window);
  303.  
  304. VOID __saveds             MouseBlanker(VOID);
  305.  
  306. VOID __regargs             UpdateNode(struct WindowNode *Node,struct Window *Window);
  307. struct WindowNode * __regargs     NewNode(struct Window *Window);
  308.  
  309. VOID                 TurnOff(VOID);
  310. VOID                 TurnOn(VOID);
  311.  
  312.     /* The window and mouse pointer access list. */
  313.  
  314. struct SignalSemaphore     WindowSemaphore;
  315. struct List         WindowList;
  316.  
  317.     /* Miscellaneous mouse blanker counters and flags. */
  318.  
  319. ULONG             KeyBlankUseCnt    = 0,
  320.              KeyBlankCount    = 0;
  321. BYTE             AllSpritesOff    = FALSE,
  322.              KeyBlankStop    = FALSE;
  323.  
  324.     /* The table of patches to install. */
  325.  
  326. struct PatchInfo PatchTable[] =
  327. {
  328.     NewClearPointer,    (LONG)&LVOClearPointer,        (ULONG *)&OldClearPointer,
  329.     NewSetPointer,        (LONG)&LVOSetPointer,        (ULONG *)&OldSetPointer,
  330.     NewOpenWindowTagList,    (LONG)&LVOOpenWindowTagList,    (ULONG *)&OldOpenWindowTagList,
  331.     NewOpenWindow,        (LONG)&LVOOpenWindow,        (ULONG *)&OldOpenWindow,
  332.     NewCloseWindow,        (LONG)&LVOCloseWindow,        (ULONG *)&OldCloseWindow
  333. };
  334.  
  335.     /* An entirely transparent sprite. */
  336.  
  337. UWORD __chip BlankSprite[(2 + 1) * 2] =
  338. {
  339.     0x0000,0x0000,
  340.  
  341.     0x0000,0x0000,
  342.  
  343.     0x0000,0x0000
  344. };
  345.  
  346.     /* Function prototypes. */
  347.  
  348. extern VOID __asm    MonoPlot(register __a0 PLANEPTR Plane,register __d0 WORD x,register __d1 WORD y,register __d2 UWORD Modulo,register __d3 WORD